package com.itany.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.itany.cloud.service.UserService;
import com.itany.cloud.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @SentinelResource(value = "findAll",blockHandler = "exceptionHandler")
    @RequestMapping("/findAll")
    public ResponseResult findAll(){
        userService.find();
        return ResponseResult.success();
    }

    public ResponseResult exceptionHandler(BlockException e){
        return ResponseResult.fail("Sentinel限流");
    }

    @RequestMapping("/findById")
    public ResponseResult findById(){
        userService.find();
        return ResponseResult.success();
    }

}
